﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.Out;
using Domain.Entity.search;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Outstock_hService
{
    public class Outstock_hService : IOutstock_hService
    {
        private readonly IOutstock_hRepository outstock_HRepository;
        private readonly IMapper mapper;

        public Outstock_hService(IOutstock_hRepository outstock_HRepository,IMapper mapper)
        {
            this.outstock_HRepository = outstock_HRepository;
            this.mapper = mapper;
        }


        //添加出库单
        public async Task<int> AddOutstock_h(AddOutstock_hDto addOutstock_HDto)
        {
            Outstock_h outstock_H = mapper.Map<Outstock_h>(addOutstock_HDto);
            return await outstock_HRepository.AddOutstock_h(outstock_H);
        }


        //删除出库单
        public async Task<int> DeleteOutstock_h(int id)
        {
            return await outstock_HRepository.DeleteOutstock_h(id);
        }

        //高级查询
        public async Task<FenYe<Outstock_h>> GetAdvancedOutstock_h(FenYe<Outstock_h> fenYe, string? code, string? starttotal, string? endtotal, string? startdate, string? enddate, string? startnum, string? endnum, int? status, string? type, int? whid, string? createname, string? startcreatetime, string? endcreatetime, string? approvername, string? startapprovertime, string? endapprovertime, string? outuser, string? outorder)
        {
            return await outstock_HRepository.GetAdvancedOutstock_h(fenYe, code, starttotal, endtotal, startdate, enddate, startnum, endnum, status, type, whid, createname, startcreatetime, endcreatetime, approvername, startapprovertime, endapprovertime, outuser, outorder);
        }

        //根据货品id查询出库记录
        public async Task<List<Outstock_h>> GetAllOutstock_h(int procid)
        {
            return await outstock_HRepository.GetAllOutstock_h(procid);
        }


        //根据关联单号查询出库记录
        public async Task<List<Outstock_h>> GetAllOutstock_hByCode(string code)
        {
            return await outstock_HRepository.GetAllOutstock_hByCode(code);
        }

        //查询
        public async Task<FenYe<Outstock_h>> GetOutstock_h(FenYe<Outstock_h> fenYe, string? code, string? type, int? status, int? whid)
        {
            return await outstock_HRepository.GetOutstock_h(fenYe,code,type,status,whid);
        }


        //根据id查询出库单
        public async Task<Outstock_h> GetOutstock_HById(int outstockid)
        {
            return await outstock_HRepository.GetOutstock_HById(outstockid);
        }

        //客户id查
        public async Task<FenYe<Outstock_h>> GetOutstock_hCust(FenYe<Outstock_h> fenYe, int cust_id)
        {
            return await outstock_HRepository.GetOutstock_hCust(fenYe,cust_id);
        }

        //供应商id查
        public async Task<FenYe<Outstock_h>> GetOutstock_hSup(FenYe<Outstock_h> fenYe, int sup_id)
        {
            return await outstock_HRepository.GetOutstock_hSup(fenYe,sup_id);
        }

        //出库统计
        public async Task<Outstock_hTJResult> Outstock_hTJ(string? timeType, string? code, int? whid, string? instarttime, string? inendtime, string? starttime, string? endtime, string outtype, int? page, int? pagesize)
        {
            return await outstock_HRepository.Outstock_hTJ(timeType,code,whid,instarttime,inendtime,starttime,endtime,outtype,page,pagesize);
        }

        //修改出库单
        public async Task<int> UpdateOutstock_h(UpdateOutstock_hDto updateOutstock_HDto)
        {
            Outstock_h outstock_H = mapper.Map<Outstock_h>(updateOutstock_HDto);
            return await outstock_HRepository.UpdateOutstock_h(outstock_H);
        }


        //修改单据状态(审核)
        public async Task<int> UpdateStatus(int outstockid, int status, string approvername, string approvertime)
        {
            return await outstock_HRepository.UpdateStatus(outstockid,status,approvername,approvertime);
        }


        //修改单据状态(撤销)
        public async Task<int> UpdateStatus(int outstockid, int status)
        {
            return await outstock_HRepository.UpdateStatus(outstockid, status);
        }
    }
}
